#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>

int gettime(int i)
{
    static struct timeval tv1;
    struct timeval tv2;
    if(i == 0)
    {
        gettimeofday(&tv1, NULL);
        return 0;
    }else
    {
        gettimeofday(&tv2, NULL);
        return tv2.tv_sec * 1000000 + tv2.tv_usec - tv1.tv_sec * 1000000 - tv1.tv_usec;
    }

}
/*#define SIZE (1024 * 1024 * 10)*/
#define SIZE (1024 * 1024 * 10)
long long buf[SIZE];
int main(int argc, char *argv[])
{
    int i;
    int time;

    memset(buf, 0, SIZE * 8);
    gettime(0);

    for(i = 0; i < SIZE; i++)
    {
        buf[i] = i;
    }
    time = gettime(1);
    printf("time1 = %d\n", time);
    
    gettime(0);
    for(i = 0; i < SIZE; i++)
    {
        buf[i] = i;
    }
    time = gettime(1);
    printf("time2 = %d\n", time);
    printf("speed: %dMB/S\n", SIZE * 8 / time);

    return 0;
}
